
//
//  DiscoverCollectionViewCellOfContentViewFourth.m
//  XYFMApp
//
//  Created by 岁变 on 16/8/31.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "DiscoverCollectionViewCellOfContentViewFourth.h"
#import "XYMacro.h"

@implementation DiscoverCollectionViewCellOfContentViewFourth

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _backImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_backImageView];
        
        _frontImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"find_anchor_cover"]];
        [self.contentView addSubview:_frontImageView];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.numberOfLines = 2;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_titleLabel];
        
        _sourceLabel = [[UILabel alloc] init];
        _sourceLabel.font = [UIFont systemFontOfSize:12];
        _sourceLabel.textColor = [UIColor colorWithRed:0.52 green:0.54 blue:0.55 alpha:1.00];
        _sourceLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_sourceLabel];
        
    }
    return self;
}


- (void)setModel:(DiscoverModelFirstPopularity *)model {
    
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:model.content_img] placeholderImage:PLACEHOLDERIMAGE];
    _titleLabel.text = model.content_title;
    _sourceLabel.text = model.content_link;

}



- (void)layoutSubviews {
    [super layoutSubviews];
    
    [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(1);
        make.left.equalTo(self.contentView.mas_left).with.offset(1);
        make.right.equalTo(self.contentView.mas_right).with.offset(-1);
        make.height.equalTo(_backImageView.mas_width);
    }];
    
    [self.contentView layoutIfNeeded];
    _backImageView.clipsToBounds = YES;
    _backImageView.layer.cornerRadius = _backImageView.frame.size.width / 2;
    
    [_frontImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.height.equalTo(_frontImageView.mas_width);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_frontImageView.mas_bottom).with.offset(5);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.height.mas_offset(20);
    }];
    
    [_sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo (self.contentView.mas_right).with.offset(0);
        make.height.mas_offset(20);
    }];

    
    
    
    
}



@end
